package com.ktg.web.mainData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.mainData.MdClient;
import com.ktg.ktgcommon.domain.mainData.MdVendor;
import com.ktg.ktgcommon.query.QueryVendor;
import com.ktg.ktgcommon.result.R;
import com.ktg.service.VendorManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class VendorManagerController {


    @Autowired
    private VendorManagerService vendorManagerService;

    @PostMapping("/vendor/checkListVendor")
    public R checkListVendor(String vendorCode, String vendorName,
                             String vendorNick, String vendorEn,
                             String enableFlag,
                             @RequestParam(defaultValue = "1") Integer pageNo,
                             @RequestParam(defaultValue = "5") Integer pageSize){
        QueryVendor queryVendor=new QueryVendor();
        queryVendor.setVendorEn(vendorEn);
        queryVendor.setVendorCode(vendorCode);
        queryVendor.setVendorName(vendorName);
        queryVendor.setVendorNick(vendorNick);
        queryVendor.setEnableFlag(enableFlag);

        System.out.println(queryVendor);
        Page<MdVendor> page = new Page<>(pageNo, pageSize);

        Page<MdVendor> selectPage = vendorManagerService.selectPage(page, queryVendor);
        return R.OK(selectPage);
    }
    @PostMapping("/vendor/checkVendorById/{vendorId}")
    public R checkVendorById(@PathVariable Long vendorId){
        MdVendor mdVendor= vendorManagerService.checkVendorById(vendorId);
        return R.OK(mdVendor);
    }
    @PostMapping("/vendor/AddOrChVendor")
    public R AddOrChVendor(MdVendor mdVendor){
        System.out.println(mdVendor);
        Integer integer= vendorManagerService.AddOrChVendor(mdVendor);
        return R.OK(integer);
    }
    @DeleteMapping("/vendor/delVendor/{vendorId}")
    public R delVendor(@PathVariable Long vendorId){
        Integer integer= vendorManagerService.delVendor(vendorId);
        return R.OK(integer);
    }
    @DeleteMapping("/vendor/delVendorIdArray")
    public R delVendorIdArray(@RequestBody List<Long> arrayVendorId){
        Integer integer = vendorManagerService.delVendorIdArray(arrayVendorId);
        return R.OK(integer);
    }
}
